home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / B_SESSIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  10.2 KB  |  315 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------            KopyRong (K) 1987.  ALL RIGHTS REVERSED.       */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*                This module was written by Vince Perriello                */
  12. /*           (based heavily on a similar work by Wynn Wagner III)           */
  13. /*                with modifications done by Bob Hartman                    */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                   BinkleyTerm Mail Session Initiator                     */
  17. /*                                                                          */
  18. /*   This  software  package is being distributed WITH FULL SOURCE CODE     */
  19. /*   with the  following  conditions:    1)  If  anything awful happens     */
  20. /*   because  you  use    it   (or  don't  use  it),  you  accept  full     */
  21. /*   responsibility;  2) you  don't start making tons of voice calls to     */
  22. /*   the authors to complain or  make  suggestions  about enhancements,     */
  23. /*   useful or otherwise;  3) you  do not reuse this code in commercial     */
  24. /*   products without specific permission to do so  from  the  authors;     */
  25. /*   4) If you find any problems you send  fixes  to  the  authors  for     */
  26. /*   inclusion  in  updates;    5) You find some way  to  express  your     */
  27. /*   appreciation  for  this  method of distribution, either by writing     */
  28. /*   code or  application  notes,  or  just sending along a "Thank You"     */
  29. /*   message.                                                               */
  30. /*                                                                          */
  31. /*   There is  copyrighted  code  in  this product.  We either wrote it     */
  32. /*   ourselves or got  permission  to use it.  Please don't force us to     */
  33. /*   pay a lawyer --  have some respect for our motives and don't abuse     */
  34. /*   this "license".                                                        */
  35. /*                                                                          */
  36. /*                                                                          */
  37. /*--------------------------------------------------------------------------*/
  38.  
  39. #include <stdio.h>
  40. #include <signal.h>
  41. #include <ctype.h>
  42. #include <conio.h>
  43.  
  44. #define WAZOO_SECTION
  45. #define MATRIX_SECTION
  46.  
  47. #include "com.h"
  48. #include "xfer.h"
  49.  
  50. extern char BBSwelcome[];
  51.  
  52. int opus_maj;
  53. int opus_min;
  54. int got_arcmail;
  55. int got_bundle;
  56. int got_mail;
  57. int sent_mail;
  58. int remote_zone;
  59. int remote_net;
  60. int remote_node;
  61. int remote_point;
  62. int remote_capabilities;
  63. char *remote_sysop = "                              ";
  64. char *remote_password;
  65. extern int mail_only;
  66. extern int hup;
  67. extern int boss_net, boss_node;
  68. extern int BBStimeout;
  69. extern int cur_event;
  70. extern int un_attended;
  71. extern int fullscreen;
  72. extern char *BBSbanner;
  73. char *BBSesc = "\rPress ESCape to enter BBS.\r";
  74. char *noBBS = "\r\rProcessing Mail. Please hang up.\r\r";
  75. char no_pickup = 0;
  76.  
  77. b_session(was_initiator)
  78. int was_initiator;
  79. {
  80.    long t1,t2,t3,timerset();
  81.    unsigned char i, j, d;
  82.    char *c;
  83.    char buff[128];
  84.  
  85.    if (un_attended && fullscreen)
  86.       {
  87.       gotoxy (69, 7);
  88.       cprintf ("%-2d Connect", cur_event + 1);
  89.       }
  90.  
  91.    /* Remove the old .REQ files */
  92.    for (i = 0; i < 10; i++)
  93.       {
  94.       if (ctl.alias[i].net == 0)
  95.          break;
  96.       sprintf( buff, "%s%04x%04x.REQ", ctl.filepath,ctl.alias[i].net,ctl.alias[i].node);
  97.       unlink (buff);
  98.       }
  99.  
  100.    remote_capabilities = 0;
  101.    if (was_initiator) goto initiate_outbound;
  102. /*
  103.  *    INBOUND -- meaning we were connected to by another system.
  104.  */
  105. initiate_inbound:
  106.       /* First a five second delay, or a char is found */
  107.       t2 = timerset (500);
  108.       i = 0;
  109.  
  110.       /* As long as we have carrier, and 5 seconds is not up, and no */
  111.       /* special chars have been received, just continue looping */
  112.       while (CARRIER && (!timeup(t2)) && (i == 0))
  113.          {
  114.          if ((i = PEEKBYTE()) >= 0)
  115.             {
  116.             switch (i&0x7f)
  117.                {
  118.                case CR:
  119.                case LV:
  120.                case ' ':
  121.                case TSYNC:
  122.                case YOOHOO:
  123.                case ENQ:
  124.                case ESC:
  125.                   continue; 
  126.                default:
  127.                   TIMED_READ(0);
  128.                }
  129.             }
  130.          i = 0;
  131.          }
  132.  
  133.       sprintf (buff, "\r\r* Network Address %d:%d/%d.%d Using %s",
  134.          ctl.our_zone, boss_net, boss_node,
  135.          (boss_net == ctl.alias[0].net) ? 0 : ctl.alias[0].node, ANNOUNCE);
  136.       c = buff;
  137.  
  138.       SENDCHARS (c, strlen (c), 1);
  139.  
  140.       t2 = timerset (BBStimeout);            /* 20 second timeout    */
  141.  
  142.       if (strlen(BBSbanner) != 0)        /* If BBS name spec'ed, */
  143.          {
  144.          SENDBYTE('\r');            /* make sure user gets  */
  145.          SENDBYTE('\n');            /* a full cr/lf...      */
  146.  
  147.          c = BBSbanner;                /* use BBS name         */
  148.  
  149.          SENDCHARS (c, strlen (c), 1);
  150.  
  151.          SENDBYTE('\r');            /* make sure user gets  */
  152.          SENDBYTE('\n');            /* a full cr/lf...      */
  153.          }
  154.  
  155.       if (!mail_only)
  156.          {
  157.          c = BBSwelcome;
  158.          while (*c && CARRIER)
  159.             {
  160.             /* Are we at the EOF? */
  161.             if (*c == 0x1a)
  162.                break;
  163.  
  164.             SENDBYTE (*c);
  165.             ++c;
  166.             }
  167.          }
  168.  
  169. play_banner:
  170.       if (mail_only)                /* If no BBS allowed,   */
  171.             c = noBBS;                /* tell human to git    */
  172.       else
  173.             c = BBSesc;                /* or hit ESC for BBS   */
  174.  
  175.       SENDCHARS (c, strlen (c), 1);
  176.  
  177. get_handshake:
  178.       while (CARRIER && (!timeup(t2)))
  179.          {
  180.          i = PEEKBYTE()&0xff;        /* Get the next char    */
  181.      switch (i)
  182.               {
  183.             case 0xff:            /* No character there   */
  184.             continue;
  185.  
  186.         case YOOHOO:        /* Looks like an Opus   */
  187. got_a_yoohoo:
  188.               if (get_YOOHOO(1))        /* Get its HELLO string */
  189.                return(WaZOO(0));    /* And do WaZOO!!!      */
  190.             else if (!hup)
  191.                goto get_handshake;    /* bad hello, try again */
  192.             else return;
  193.  
  194.         case TSYNC:            /* Looks like an FTSC   */
  195.             /* Here we should probably really see if it is an FTSC      */
  196.             /* See if we get anything within 2 seconds, if not, then it */
  197.             /* is FTSC.  If we get another TSYNC, it also means FTSC.   */
  198.             /* BUT, if we get a YOOHOO, then we can do WaZOO, and it    */
  199.             /* just means that we missed the first YOOHOO - lucky us.   */
  200.             CLEAR_INBOUND ();
  201.             t3 = timerset (200); /* Set for 2 seconds */
  202.             d = 0;
  203.             while (CARRIER && (!timeup (t3)) && (!d))
  204.                {
  205.                if ((i = PEEKBYTE()) >= 0)
  206.                   {
  207.                   switch (i)
  208.                      {
  209.                      case YOOHOO:
  210.                         goto got_a_yoohoo;
  211.  
  212.                      case TSYNC:
  213.                         d = 1;
  214.                         break;
  215.  
  216.                      default:
  217.                         TIMED_READ(0);
  218.                      }
  219.                   }
  220.                }
  221.             if (CARRIER)
  222.                return (FTSC_receiver(0));
  223.             else
  224.                return (1);
  225.  
  226.         case CR:
  227.             i = TIMED_READ(0);        /* Eat the CR           */
  228.             goto play_banner;        /* Play the banner again*/
  229.  
  230.             case ESC:            /* This will be for BBS */
  231.             if (!mail_only)        /* If BBS operation OK, */
  232.                goto spawnBBS;        /* go do it...          */
  233.  
  234.         default:
  235.             i = TIMED_READ (0);        /* Eat the character    */
  236.              }
  237.           }
  238. spawnBBS:
  239.     if (CARRIER && !mail_only)
  240.         BBSexit();
  241.     return;
  242.  
  243. /*
  244.  *    OUTBOUND -- meaning call was made by us.
  245.  */
  246.  
  247. initiate_outbound:
  248.  
  249.    if (FTSC_Whack_CR())
  250.       {
  251.       return (-1);
  252.       }
  253.    t1 = timerset(3000);                /* set 30 second timeout */
  254.    j = 0;
  255.    while (!timeup(t1) && CARRIER)        /* till then or CD lost  */
  256.        {
  257.         SENDBYTE(YOOHOO);            /* Initiate session?     */
  258.       SENDBYTE(TSYNC);
  259.  
  260.       t2 = timerset (300);
  261.       while (CARRIER && (!timeup(t2)))
  262.          {
  263.          i = TIMED_READ (0);
  264.  
  265.          /* Because Fido v12 has a tendency to echo the YooHoo and throw */
  266.          /* off the value of j which we use later on.  We just ignore it */
  267.          if ((i&0x7f) == (YOOHOO&0x7f))
  268.             continue;
  269.  
  270.          switch (i)
  271.             {
  272.             case ENQ:
  273.                 if (send_YOOHOO(1))        /* Send Hello packet,    */
  274.                     return(WaZOO(1));       /* do WaZOO and leave    */
  275.                else
  276.                   return(-1);
  277.                break;
  278.  
  279.             case 0x00:
  280.             case 0x01:
  281.             case 'C':
  282.                if (j == 'C')
  283.                   return (FTSC_sender(0));
  284.                break;
  285.  
  286.             case 0xfe:
  287.             case 0xfffe:
  288.                if (j == 0x01)
  289.                   return (FTSC_sender(0));
  290.                break;
  291.  
  292.             case 0xff:
  293.             case 0xffff:
  294.                if (j == 0x00)
  295.                   return (FTSC_sender(0));
  296.                break;
  297.  
  298.             case NAK:
  299.                if (j == NAK)
  300.                   return (FTSC_sender(0));
  301.                break;
  302.             }
  303.          if ((i != 0xffff) && (i != 0xff))
  304.             j = i;
  305.          }
  306.        }
  307. }
  308.  
  309. b_init()
  310. {
  311. opus_maj = opus_min = got_arcmail = got_bundle = got_mail = sent_mail = 0;
  312. remote_zone = remote_net = remote_node = remote_point = 0;
  313. remote_capabilities = 0;
  314. }
  315.